//
//  OPHomeGoodClassView.m
//  OpenPractice
//
//  Created by red on 2021/11/3.
//  Copyright © 2021 tanyuehong. All rights reserved.
//

#import "SCCustomButton.h"
#import "OPHomeContentCell.h"
#import "OPHomeGoodClassView.h"

@interface OPHomeGoodClassView ()

@property (nonatomic,strong) UILabel *titleLable;
@property (nonatomic,strong) SCCustomButton *moreBtn;

@end

@implementation OPHomeGoodClassView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self addSubview:self.titleLable];
        [self addSubview:self.moreBtn];
        [self layoutMySubview];
        [self updateGoodClassData:@[@(OPHomeContentCellClass),@(OPHomeContentCellClass),@(OPHomeContentCellClass)]];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)layoutMySubview {
    [self.titleLable  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.width.equalTo(@80);
        make.height.equalTo(@20);
        make.top.equalTo(self).offset(20);
    }];
    
    [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-30);
        make.width.equalTo(@30);
        make.height.equalTo(@20);
        make.top.equalTo(self).offset(20);
    }];
}

- (void)updateGoodClassData:(NSArray *)clsData {
    for (NSInteger i=0; i<clsData.count; i++) {
        OPHomeContentCell *myCell = [[OPHomeContentCell alloc] initWithContentData:clsData[i]];
        [self addSubview:myCell];
        [myCell mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(@(50 + i*120));
            make.width.equalTo(self);
            make.left.equalTo(self);
            make.height.equalTo(@120);
        }];
    }
}

- (UILabel *)titleLable {
    if (!_titleLable) {
        _titleLable = [[UILabel alloc] init];
        _titleLable.text = @"好课推荐";
        _titleLable.textColor = kTYH333333TextColor;
        _titleLable.font = [UIFont boldSystemFontOfSize:16];
    }
    return _titleLable;
}

- (UIButton *)moreBtn {
    if (!_moreBtn) {
        _moreBtn = [[SCCustomButton alloc] init];
        [_moreBtn setImage:[UIImage imageNamed:@"home_good_class_more"] forState:UIControlStateNormal];
        _moreBtn.imagePosition = SCCustomButtonImagePositionRight;
        _moreBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_moreBtn setTitleColor:kTYH666666TextColor forState:UIControlStateNormal];
        [_moreBtn setTitle:@"更多" forState:UIControlStateNormal];
        _moreBtn.interTitleImageSpacing = -8;
    }
    return _moreBtn;
}

@end
